﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Web.Security;

namespace HashFoo.Rest.Server
{
    /// <summary>
    /// Uses the default Asp.Net <see cref="MembershipProvider"/> and <see cref="RoleProvider"/> as a backing source.
    /// </summary>
    public class AspDefaultMembershipProvider : IMembershipProvider
    {
        /// <summary>
        /// Returns true if the username and password are valid.
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public bool ValidateUser(string userName, string password)
        {
            return Membership.Provider.ValidateUser(userName, password);
        }

        /// <summary>
        /// The the roles (as strings) that a user belongs to.
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public string[] GetRoles(string userName)
        {
            return Roles.GetRolesForUser(userName);
        }
    }
}